package com.cdtye.itps.cms.service.origindata;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.common.webcore.enums.YesNoEnum;
import com.cdtye.itps.cms.dao.origindata.entity.JcjcDetectC1Job;
import com.cdtye.itps.cms.dao.origindata.vo.JcjcDetectC1JobVo;
import com.cdtye.itps.cms.mapper.origindata.JcjcDetectC1JobMapper;
import com.cdtye.itps.cms.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class JcjcDetectC1JobService extends BaseService<JcjcDetectC1JobMapper, JcjcDetectC1Job> {

    @Autowired
    private JcjcDetectC1JobMapper baseMapper;

    /**
     * 按是否获取标识indexFlag查询
     * @return
     */
    public List<JcjcDetectC1Job> selectIndexFlagByUnitDeptCode(String unitDeptCode){
        QueryWrapper<JcjcDetectC1Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("index_flag", YesNoEnum.NO.getCode());
        //queryWrapper.eq("unit_dept_code", unitDeptCode);
        List<JcjcDetectC1Job> list = baseMapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 新增
     * @return
     */
    public boolean insertJcjcDetectC1Job(JcjcDetectC1Job jdc){
        return this.saveOrUpdate(jdc);
    }

    /**
     * 修改
     * @return
     */
    public int updateJcjcDetectC1Job(JcjcDetectC1Job jdc){
        UpdateWrapper<JcjcDetectC1Job> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("detect_job_id",jdc.getDetectJobId());
        return baseMapper.update(jdc,updateWrapper);
    }

    public IPage<Map<String,Object>> listPage(JcjcDetectC1JobVo vo){
        if (vo.getEndDate()!=null) {
            String endDate = DateUtils.DateToString(vo.getEndDate(),"yyyy-MM-dd")+" 23:59:59";
            vo.setEndDate(DateUtils.StringToDate(endDate,"yyyy-MM-dd HH:mm:ss"));
        }
        return baseMapper.listPage(vo.page(),vo);
    }
}
